<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ include file="/wesite/view/common/base.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>站内消息</title>
    <%@ include file="/wesite/view/common/common.jsp" %>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <%@ include file="/wesite/view/common/common.jsp" %>
</head>
<style>

    .station-news-list ul {
        padding-left: .533333rem;
        background-color: #fff;
    }

    .station-news-list ul li {
        position: relative;
        width: 100%;
        height: 2.666667rem;
        border-bottom: 1px solid #eee;
        font-size: .693333rem;
        color: #222;
        padding: .573333rem 2.4rem .573333rem 0;
    }

    .station-news-list ul li:last-child {
        border-bottom: none;
    }

    .station-news-list ul li p {
        line-height: 1;
        overflow: hidden;
        white-space: nowrap;
        -ms-text-overflow: ellipsis;
        text-overflow: ellipsis;:;
    }

    .station-news-list ul li .news-tit-time {
        font-size: .5866667rem;
        color: #999;
        margin-bottom: .266667rem;
    }

    .station-news-list ul li .arrow-r {
        background: url(${webctx}/images/ico-arrow-r.png) 0 0 no-repeat;
        background-size: 0.8rem;
        width: 0.8rem;
        height: 0.8rem;
        position: absolute;
        right: 0.8rem;
        top: 50%;
        margin-top: -0.4rem;
    }
</style>
<body>
<div style="padding-top: 1rem;" class="station-news-list">
    <ul class="list">

    </ul>
</div>
<div class="empty-page" style="display: none;">
    <span class="txt-kong-img"><img src="${webctx}/images/Thome.png"></span>
    <p>您尚未收到任何消息</p>
</div>
<div id="list" style=" margin: 10px 0; color: #999; text-align: center;display: none;"></div>
<div class="h98 js-hover-layer"></div>
</body>
</html>
<script src="${ctx }/plugins/artTemplate/dist/template.js"></script>
<script src="${webctx}/script/aui-toast.js"></script>
<script type="text/javascript" src="${webctx}/script/aui-scroll.js"></script>
<script type="text/javascript" src="${webctx}/script/api.js"></script>

<script>
    function details(id) {
        window.location.href = "${ctx}/we/user/MessageDetails?id=" + id;
    }
    var hotsLoading = false;
    var IPageNo = 1;
    var totalPage = 1;
    function loadproducts() {
        if (hotsLoading) {
            return false;
        } else {
            hotsLoading = true;
        }
        $("#list").text("正在加载 ...").show();

        $w.httpRequest({
            url: apiroot + "/we/user/myMessage",
            method: "get",
            data: {
                "pno": IPageNo,
            },
            ok: function (ret) {
                hotsLoading = false;
                var data = ret.Data;
                var num = data.resultCount;     //判断是否有消息
                totalPage = data.pageCount;
                productdata = data.list;
                if(num == 0){
                    $(".empty-page").css("display", "block");
                    $("#list").hide();
                }
                if (productdata && productdata.length > 0) {
                    for (var i = 0; i < productdata.length; i++) {
                        if (productdata[i].B_chanjia && productdata[i].B_chanjia.length > 11) {
                            productdata[i].B_chanjia = productdata[i].B_chanjia.substr(0, 11) + "...";
                        }
                    }
                    IPageNo++;
                    $("#list").hide();
                    showProducts();
                } else {
                    $("#list").text("已加载全部");
                    IPageNo = 0;
                }
            }
        })
    }
    function showProducts() {
        var h = template('productHtml_list', {
            ctx: ctx,
            fileserver: getRandomFileserver(),
            isuserauth: isuserauth,
            islogin: islogin,
            list: productdata
        });
        $(".list").append(h);
    }
    $(function () {
        loadproducts();
        var buttomHeight = 12;
        var scroll = new auiScroll({
            listen: true, //是否监听滚动高度，开启后将实时返回滚动高度
            distance: buttomHeight, //判断到达底部的距离，isToBottom为true
        }, function (ret) {
            if (ret.isToBottom) {
                if (IPageNo > 0 && IPageNo <=totalPage) {
                    var toast = new auiToast({});
                    toast.loading({
                        title: "加载中",
                        duration: 300
                    }, function () {
                        setTimeout(function () {
                            toast.hide();
                        }, 300)
                    });
                    loadproducts();
                }
            }
        });
    });
</script>
<script type="text/html" id="productHtml_list">
    {{each list as info i}}
    <li>
        <a style="display: block;" href="javascript:details('{{info.id}}');">
            {{if info.isread ==0}}
            <p class="news-tit-time" style="color: #333;">{{info.create_time}} </p>
            <p style="color: #333;">{{info.title}}</p>

            {{else }}
            <p class="news-tit-time" style="color: #999;">{{info.create_time}} </p>
            <p class="fide" style="color: #999;">{{info.title}}</p>
            {{/if}}

            <span class="arrow-r"></span>
        </a>
    </li>
    {{/each}}

</script>